package com.lepu.app.fun.tool.ymsjb;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ListView;

import com.app.utils.LoginUtil;
import com.core.lib.application.BaseFragmentActivity;
import com.core.lib.utils.main.UtilityBase;
import com.eyzhs.app.R;
import com.lepu.app.fun.tool.ymsjb.adapter.ToolYiMiaoAdapter;
import com.lepu.app.fun.tool.ymsjb.bean.BeanToolYiMiao;
import com.lepu.app.widget.CustomTopBarNew;
import com.lepu.app.widget.CustomTopBarNew.OnTopbarNewLeftLayoutListener;
import com.lepu.app.widget.CustomTopBarNew.OnTopbarNewRightButtonListener;

public class YiMiaoActivity extends BaseFragmentActivity implements
		OnTopbarNewLeftLayoutListener,OnTopbarNewRightButtonListener {
	public ListView mListView;
	public ToolYiMiaoAdapter mAdapter;
	public ArrayList<BeanToolYiMiao> mArrayList;
	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {

		mNeedStatusBar = false;
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tool_yimiao_activity);

		UtilityBase.setStatusBarRes(this, R.color.color_daichan, true);
		init();
	}

	@Override
	public void onResume() {
		super.onResume();
		
		if(!BeanToolYiMiao.isExist(LoginUtil.getUserId())){
			ArrayList<BeanToolYiMiao> list = BeanToolYiMiao.getDataByUid("");
			for(int i=0; i<list.size(); i++){
				BeanToolYiMiao bean = list.get(i);
				bean.uid = LoginUtil.getUserId();
				BeanToolYiMiao.insert(bean);
			}
		}
		
		mArrayList = BeanToolYiMiao.getDataByUid(LoginUtil.getUserId()); 
		
		mAdapter = new ToolYiMiaoAdapter(this, mArrayList);
		mListView.setAdapter(mAdapter);
	}
	
	@Override
	public void onDestroy() {
		super.onDestroy();
	}

	/**
	 * 添加页面动画，需要重写这个方法，
	 */
	@Override
	public void onBackPressed() {
		finish(true);
	}

	@Override
	public void onTopbarLeftLayoutSelected() {
		finish(true);
	}

	@Override
	public void onTopbarRightButtonSelected() {
		startActivity(new Intent(this, YiMiaoAddActivity.class),true);
	}
	
	/**
	 * 初始化方法
	 */
	private void init() {
		// topbar
		CustomTopBarNew topbar = (CustomTopBarNew) findViewById(R.id.topbar);
		topbar.setTopbarTitle("疫苗时间表");
		topbar.setRightText("设置");
		topbar.setTopbarBackground(R.color.color_daichan);
		topbar.setonTopbarNewLeftLayoutListener(this);
		topbar.setOnTopbarNewRightButtonListener(this);

		mListView = (ListView) findViewById(R.id.listView);
		

		
	}
	
}
